<template>
	<view class="template-news tn-safe-area-inset-bottom">

		<view class="tn-navbg" :style="{height: vuex_custom_bar_height + 'px'}">
			<!-- 顶部自定义导航 -->
			<tn-nav-bar fixed alpha customBack>
				<view slot="back" class='tn-custom-nav-bar__back' @click="goBack">
					<text class='icon tn-icon-left'></text>
					<text class='icon tn-icon-home-capsule-fill'></text>
				</view>
			</tn-nav-bar>
		</view>

		<view class="tn-margin-top-xs" :style="{paddingTop: vuex_custom_bar_height + 20 + 'px'}">
			<view class="nav_title--wrap">
				<view class="nav_title tn-main-gradient-blue">
					<!-- <text class="tn-icon-fire tn-padding-right-sm"></text> -->
					{{detail.title || ''}}
					<!-- <text class="tn-icon-fire tn-padding-left-sm"></text> -->
				</view>
			</view>

			<view class="news-img tn-padding">
				<rich-text :nodes="detail.content"></rich-text>
			</view>

		</view>

		<view class="tn-margin-top tn-padding-top-sm tn-margin-bottom">
			<view class="see">
				<view class="justify-content-item tn-flex tn-flex-col-center">
					<view style="margin-left: 15rpx;margin-right: 6rpx;transform: scale(0.85);">
						<tn-avatar-group :lists="groupList" size="sm"></tn-avatar-group>
					</view>
					<text class="tn-color-gray">{{ detail.readNum || '666' }}人 (转发得<text
							class="tn-color-red">1-100</text>元红包)</text>
				</view>
				<view class="justify-content-item tn-color-gray tn-text-center tn-margin-right"
					style="padding-top: 5rpx;">
					<text class="tn-icon-fire tn-text-lg" style="padding-right: 5rpx;"></text>
					<text class="tn-padding-right tn-text-df">{{ detail.readNum }}</text>
					<text class="tn-icon-like-lack tn-text-lg" style="padding-right: 5rpx;"></text>
					<text class="tn-text-df">{{ detail.shareNum }}</text>
				</view>

			</view>
		</view>

		<!-- 边距间隔 -->
		<view class="tn-strip-bottom"></view>

		<view class="tn-flex tn-flex-row-between">
			<view class="justify-content-item tn-margin tn-text-bold tn-text-xl">
				Ta们都在看
			</view>
			<view class="justify-content-item tn-margin tn-text-lg tn-color-grey" @click="tn('/homePages/hot')">
				<text class="tn-padding-xs">全部</text>
				<text class="tn-icon-topics"></text>
			</view>
		</view>


		<view class="">

			<block v-for="(item,index) in news" :key="index">
				<!-- 单图大图文 -->
				<block v-if="item.imgLen == 1">
					<view class="article-shadow tn-margin tn-padding-sm" @click="tn(`/pageA/news/news?id=${item.id}`)">
						<view class="image-pic" :style="'background-image:url(' + item.url + ')'">
							<view class="image-design">
							</view>
						</view>
						<view class="tn-margin-top tn-padding-bottom-sm">
							<view class="tn-text-xl tn-text-bold clamp-text-2 tn-text-justify">
								<text class="">{{ item.title }}</text>
							</view>

							<view class="tn-flex tn-flex-row-between tn-flex-col-between tn-margin-top-sm">
								<!-- <view v-for="(label_item,label_index) in item.label" :key="label_index"
								class="justify-content-item tn-tag-content__item tn-margin-right tn-text-sm tn-text-bold">
								<text class="tn-tag-content__item--prefix">#</text> {{ label_item }}
							</view> -->
								<view class="justify-content-item tn-color-gray tn-text-center"
									style="padding-top: 5rpx;">
									<text class="tn-icon-fire tn-text-lg" style="padding-right: 5rpx;"></text>
									<text class="tn-padding-right tn-text-df">{{ item.readNum }}次观看</text>
									<text class="tn-icon-moments tn-text-lg" style="padding-right: 5rpx;"></text>
									<text class="tn-text-df">{{item.shareNum}}人(转发得<text
											class="tn-color-red">1-100</text>红包)</text>

								</view>
							</view>
						</view>
					</view>
				</block>
				<!-- 三图图文 -->
				<block v-if="item.imgLen == 3">
					<view class="article-shadow tn-margin" @click="tn(`/pageA/news/news?id=${item.id}`)">
						<view class="" style="padding: 15rpx 10rpx 0 10rpx;">
							<tn-grid hoverClass="none" :col="3">
								<block v-for="(image_item,image_index) in item.imgList" :key="image_index">
									<view class="" style="width: 33.3%;">
										<view class="image-pic tn-margin-xs"
											:style="'background-image:url(' + image_item + ')'">
											<view class="image-article">
											</view>
										</view>
										<!-- <image
			        class="blogger__main-image blogger__main-image--3"
			        :src="image_item"
			        mode="aspectFill"
			      ></image> -->
									</view>
								</block>
							</tn-grid>
						</view>


						<view class="tn-margin-xl tn-padding-bottom-sm">
							<view class="tn-text-lg tn-text-bold clamp-text-2 tn-text-justify">
								<text class="">{{ item.title }}</text>
							</view>
							<!-- <view class="tn-padding-top-xs" style="min-height: 90rpx;">
			  <text class="tn-text-df tn-color-gray clamp-text-2 tn-text-justify">
			    {{ item.desc }}
			  </text>
			</view> -->
							<view class="tn-flex tn-flex-row-between tn-flex-col-between tn-margin-top-sm">
								<!-- <view v-for="(label_item,label_index) in item.label" :key="label_index"
									class="justify-content-item tn-tag-content__item tn-margin-right tn-text-sm tn-text-bold">
									<text class="tn-tag-content__item--prefix">#</text> {{ label_item }}
								</view> -->
								<view class="justify-content-item tn-color-gray tn-text-center"
									style="padding-top: 5rpx;">
									<text class="tn-icon-fire tn-text-lg" style="padding-right: 5rpx;"></text>
									<text class="tn-padding-right tn-text-df">{{ item.readNum }}次观看</text>
									<text class="tn-icon-like-lack tn-text-lg" style="padding-right: 5rpx;"></text>
									<text class="tn-text-df">{{ item.shareNum }}人转发</text>
								</view>
							</view>
						</view>
					</view>
				</block>
			</block>

		</view>


		<!-- 悬浮按钮-->
		<view class="tn-footerfixed">

			<view class="tn-flex tn-flex-row-between ">
				<view class="tn-flex-1 justify-content-item tn-margin-xs tn-text-center">
					<tn-button backgroundColor="#05C160" padding="50rpx 0" width="98%" :fontSize="40" open-type="share">
						<text class="tn-color-white tn-text-bold" style="font-size: 40rpx;">点击分享该文章随机得1-100红包</text>
						<text class="tn-icon-wechat tn-padding-left-xs tn-color-white"></text>
						<text
							class="tn-icon-lucky-money-fill tn-padding-left-xs tn-color-red tn-text-lg red-packet"></text>
					</tn-button>
				</view>

				<!-- <view class="tn-flex-1 justify-content-item tn-margin-xs tn-text-center">
					<tn-button backgroundColor="#FBBD12" padding="40rpx 0" width="90%" :fontSize="28">
						<text class="tn-color-white">分享到朋友圈</text>
						<text class="tn-icon-like-lack tn-padding-left-xs tn-color-white"></text>
					</tn-button>
				</view> -->
			</view>

			<!-- <view class="tn-flex-1 justify-content-item tn-margin-xs tn-text-center">
				<tn-button backgroundColor="#05C160" padding="40rpx 0" width="90%" :fontSize="28" open-type="share">
					<text class="tn-color-white">分享文章得1-100元红包</text>
					<text class="tn-icon-wechat tn-padding-left-xs tn-color-white"></text>
				</tn-button>
			</view> -->

		</view>

		<view class="icon15__item--icon tn-flex tn-flex-row-center tn-flex-col-center tn-shadow-blur button-1"
			@click="tn('/pages/index/index')">
			<view class="tn-icon-home-capsule-fill tn-color-white"></view>
		</view>
		<view class="icon15__item--icon tn-flex tn-flex-row-center tn-flex-col-center tn-shadow-blur button-2">
			<button class="tn-button--clear-style" open-type="share" style="border-radius: 0;">
				<view class="tn-icon-send-fill tn-color-white red-packet"></view>
				<!-- <text class="tn-icon-lucky-money-fill tn-padding-left-xs tn-color-red tn-text-lg red-packet"></text> -->
			</button>
		</view>

		<view class='tn-tabbar-height'></view>

	</view>
</template>

<script>
	import template_page_mixin from '@/libs/mixin/template_page_mixin.js'
	export default {
		name: 'TemplateNews',
		mixins: [template_page_mixin],
		data() {
			return {
				detail: {},
				groupList: [{
						src: 'http://gyh7790.oss-cn-beijing.aliyuncs.com/buerkeji/mp/20241118/7539ffcb1879421cae85aeb7eed1b380.jpg'
					},
					{
						src: 'http://gyh7790.oss-cn-beijing.aliyuncs.com/buerkeji/mp/20241118/7539ffcb1879421cae85aeb7eed1b380.jpg'
					},
					{
						src: 'http://gyh7790.oss-cn-beijing.aliyuncs.com/buerkeji/mp/20241118/7539ffcb1879421cae85aeb7eed1b380.jpg'
					},
					{
						src: 'http://gyh7790.oss-cn-beijing.aliyuncs.com/buerkeji/mp/20241118/91fb6bc61c9f45778d207dfb8649d27e.jpg'
					}
				],
				news: [],
			}
		},
		onShareAppMessage(res) {
			let id = this.detail.id
			let fromId = ''



			return {
				title: `${this.detail.title}`,
				path: `/pageA/news/news?id=${id}&fromId=${fromId}`,
				imageUrl: `${this.detail.imgList[0]}`,
			}
		},
		onShareTimeline(res) {
			let id = this.detail.id
			let fromId = ''
			return {
				title: `${this.detail.title}`,
				path: `/pageA/news/news?id=${id}&fromId=${fromId}`,
				imageUrl: `${this.detail.imgList[0]}`,
			}
		},
		onLoad({
			id
		}) {
			if (id) {
				this.$api.getArticleDetail({
					id
				}).then((res) => {
					this.loading = false;
					this.detail = res.data
					this.getArticle()

					this.$api.mpAction({
						type: 1,
						id
					})
				}).catch((err) => {
					this.loading = false;
				})
			}

		},
		methods: {
			getArticle() {
				const randomIndex = Math.floor(Math.random() * this.detail.tagIds.length);
				this.$api.getArticle({
					tagId: this.detail.tagIds[randomIndex] || ''
				}).then((res) => {
					this.news = res.data.list.map(item => {
						return {
							...item,
							imgLen: item.imgList.length,
							url: item.imgList[0]
						}
					})
				}).catch((err) => {
					this.loading = false;
				})
			},
			// 跳转
			tn(e) {
				uni.navigateTo({
					url: e,
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	/* 胶囊*/
	.tn-custom-nav-bar__back {
		width: 100%;
		height: 100%;
		position: relative;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		box-sizing: border-box;
		background-color: rgba(0, 0, 0, 0.15);
		border-radius: 1000rpx;
		border: 1rpx solid rgba(255, 255, 255, 0.5);
		color: #FFFFFF;
		font-size: 18px;

		.icon {
			display: block;
			flex: 1;
			margin: auto;
			text-align: center;
		}

		&:before {
			content: " ";
			width: 1rpx;
			height: 110%;
			position: absolute;
			top: 22.5%;
			left: 0;
			right: 0;
			margin: auto;
			transform: scale(0.5);
			transform-origin: 0 0;
			pointer-events: none;
			box-sizing: border-box;
			opacity: 0.7;
			background-color: #FFFFFF;
		}
	}

	/* 顶部渐变*/
	.tn-navbg {
		background: linear-gradient(-120deg, #F15BB5, #9A5CE5, #01BEFF, #00F5D4);
		/* background: linear-gradient(-120deg,  #9A5CE5, #01BEFF, #00F5D4, #43e97b); */
		/* background: linear-gradient(-120deg,#c471f5, #ec008c, #ff4e50,#f9d423); */
		/* background: linear-gradient(-120deg, #0976ea, #c471f5, #f956b6, #ea7e0a); */
		background-size: 500% 500%;
		animation: gradientBG 15s ease infinite;
		position: fixed;
		top: 0;
		width: 100%;
		z-index: 100;
	}

	@keyframes gradientBG {
		0% {
			background-position: 0% 50%;
		}

		50% {
			background-position: 100% 50%;
		}

		100% {
			background-position: 0% 50%;
		}
	}

	/* 标题 start */
	.nav_title {
		-webkit-background-clip: text;
		color: transparent;
		padding-left: 8rpx;
		padding-right: 8rpx;
		text-align: center;
		font-size: 46rpx;

		&--wrap {
			position: relative;
			display: flex;
			min-height: 120rpx;
			font-size: 42rpx;
			align-items: center;
			justify-content: center;
			font-weight: bold;
			background-image: url(http://gyh7790.oss-cn-beijing.aliyuncs.com/buerkeji/mp/20241118/af94e7589feb4d40a79beac87ae9ce72.png);
			background-size: cover;
		}
	}

	/* 标题 end */

	/* 富文本图示意 start */
	.news-img {
		z-index: -1;
		padding-bottom: 40rpx;

		image {
			width: 100%;
			margin: 20rpx 0;
			// height: 3373rpx;
			// z-index: -1;
		}
	}

	/* 资讯主图 start*/
	.image-article {
		border-radius: 8rpx;
		width: 200rpx;
		height: 200rpx;
		position: relative;
	}

	.image-pic {
		border: 1rpx solid #F8F7F8;
		background-size: cover;
		background-repeat: no-repeat;
		// background-attachment:fixed;
		background-position: top;
		border-radius: 10rpx;
		// background-position: center;
	}

	.article-shadow {
		border-radius: 15rpx;
		box-shadow: 0rpx 0rpx 50rpx 0rpx rgba(0, 0, 0, 0.07);
	}

	/* 文字截取*/
	.clamp-text-1 {
		-webkit-line-clamp: 1;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		text-overflow: ellipsis;
		overflow: hidden;
	}

	.clamp-text-2 {
		-webkit-line-clamp: 2;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		text-overflow: ellipsis;
		overflow: hidden;
	}

	/* 标签内容 start*/
	.tn-tag-content {
		&__item {
			display: inline-block;
			line-height: 35rpx;
			color: #1D2541;
			background-color: #F3F2F7;
			border-radius: 10rpx;
			font-size: 22rpx;
			padding: 5rpx 15rpx;

			&--prefix {
				padding-right: 10rpx;
			}
		}
	}


	/* 大单图 start*/
	.tn-blogger-content2 {
		&__wrap {
			padding: 30rpx;
		}

		&__info {
			&__btn {
				margin-right: -12rpx;
				opacity: 0.5;
			}
		}

		&__label {
			&__item {
				line-height: 45rpx;
				padding: 0 20rpx;
				margin: 5rpx 18rpx 0 0;

				&--prefix {
					color: #00FFC8;
					padding-right: 10rpx;
				}
			}

			&__desc {
				line-height: 55rpx;
			}
		}

		&__main-image {
			box-shadow: 0rpx 5rpx 40rpx 0rpx rgba(43, 158, 246, 0.2);
			border-radius: 16rpx;

			&--1 {
				max-width: 690rpx;
				min-width: 690rpx;
				max-height: 400rpx;
				min-height: 400rpx;
			}

			&--2 {
				max-width: 260rpx;
				max-height: 260rpx;
			}

			&--3 {
				height: 212rpx;
				width: 100%;
			}
		}

		&__count-icon {
			font-size: 40rpx;
			padding-right: 5rpx;
		}
	}

	.image-design {
		padding: 160rpx 0rpx;
		font-size: 40rpx;
		font-weight: 300;
		position: relative;
	}

	.image-pic {
		background-size: cover;
		background-repeat: no-repeat;
		// background-attachment:fixed;
		background-position: top;
		border-radius: 10rpx;
	}

	/* 文章内容 end*/

	/* 底部悬浮按钮 start*/
	.tn-tabbar-height {
		min-height: 100rpx;
		height: calc(120rpx + env(safe-area-inset-bottom) / 2);
	}

	.tn-footerfixed {
		position: fixed;
		width: 100%;
		bottom: calc(30rpx + env(safe-area-inset-bottom));
		z-index: 1024;
		box-shadow: 0 1rpx 6rpx rgba(0, 0, 0, 0);

	}

	/* 底部悬浮按钮 end*/

	/* 查看*/
	.see {
		display: flex;
		justify-content: space-between;
		padding-top: 10rpx;
		border-radius: 6rpx;
		color: #666;
		line-height: 1.6;
	}

	/* 间隔线 start*/
	.tn-strip-bottom {
		width: 100%;
		border-bottom: 20rpx solid rgba(241, 241, 241, 0.8);
	}

	/* 间隔线 end*/

	.red-packet {
		display: inline-block;
		font-size: 44rpx;
		animation: shake-rotate 1s cubic-bezier(0.4, 0, 0.6, 1) infinite both;

	}

	@keyframes shake-rotate {
		0% {
			transform: translateX(0) rotate(0deg) scale(1);
		}

		20% {
			transform: translateX(8px) rotate(10deg) scale(1.2);
		}

		40% {
			transform: translateX(0) rotate(0deg) scale(1);
		}

		60% {
			transform: translateX(-8px) rotate(-10deg) scale(1.2);
		}

		80% {
			transform: translateX(0) rotate(0deg) scale(1);
		}

		100% {
			transform: translateX(0) rotate(0deg) scale(1);
		}
	}

	.button-2 {
		background-color: rgba(0, 0, 0, 0.25);
		position: fixed;
		bottom: 18%;
		right: 30rpx;
		z-index: 1001;
		border-radius: 100px;
	}

	.button-1 {
		background-color: rgba(0, 0, 0, 0.25);
		position: fixed;
		/* bottom:200rpx;
	  right: 20rpx; */
		bottom: 27%;
		right: 30rpx;
		z-index: 1001;
		border-radius: 100px;
	}

	/* 图标容器15 start */
	.icon15 {
		&__item {
			width: 30%;

			border-radius: 10rpx;
			padding: 30rpx;
			margin: 20rpx 10rpx;
			transform: scale(1);
			transition: transform 0.3s linear;
			transform-origin: center center;

			&--icon {
				width: 100rpx;
				height: 100rpx;
				font-size: 50rpx;
				border-radius: 50%;
				margin-bottom: 18rpx;
				z-index: 1;

				&::after {
					content: " ";
					position: absolute;
					z-index: -1;
					width: 100%;
					height: 100%;
					left: 0;
					bottom: 0;
					border-radius: inherit;
					opacity: 1;
					transform: scale(1, 1);
					background-size: 100% 100%;


				}
			}
		}
	}
</style>